//
//  ShareAndPrintView.m
//  koudaishuteacher
//
//  Created by koudaishu on 2018/3/9.
//  Copyright © 2018年 koudaishu. All rights reserved.
//

#import "MSShareView.h"

@interface MSShareView ()
@property (nonatomic, strong) UIView *bgView;

@property (nonatomic, strong) UIButton *weChatBtn;
@property (nonatomic, strong) UIButton *friendBtn;
@property (nonatomic, strong) UIButton *QRBtn;

@property (nonatomic, strong) UILabel *weChatLabel;
@property (nonatomic, strong) UILabel *friendLabel;
@property (nonatomic, strong) UILabel *QRLabel;

@end

@implementation MSShareView

- (instancetype)initWithFrame:(CGRect)frame{
    if (self = [super initWithFrame:frame]) {
        [self setupUI];
    }
    return self;
}

- (void)setupUI {
    self.backgroundColor = [UIColor colorWithWhite:0 alpha:0.3];
    UIButton * cancelBtn = [[UIButton alloc]init];
    kWeakSelf(self);
    [cancelBtn addTapBlock:^(UIButton *btn) {
        weakself.hidden = YES;
    }];
    [self addSubview:cancelBtn];
    [cancelBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.mas_left).offset(0);
        make.top.equalTo(self.mas_top).offset(0);
        make.right.equalTo(self.mas_right).offset(0);
        make.bottom.equalTo(self.mas_bottom).offset(0);
    }];
    
    [self addSubview:self.bgView];
    [self.bgView addSubview:self.weChatBtn];
    [self.bgView addSubview:self.friendBtn];
    [self.bgView addSubview:self.QRBtn];
    
    [self.bgView addSubview:self.weChatLabel];
    [self.bgView addSubview:self.friendLabel];
    [self.bgView addSubview:self.QRLabel];
    
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(self.mas_left);
        make.right.mas_equalTo(self.mas_right);
        make.bottom.mas_equalTo(self.mas_bottom).offset(0);
        make.height.mas_equalTo(@(213 + kViewToBottom));
    }];
    
    UILabel * title = [[UILabel alloc]init];
    title.text = @"邀请好友";
    title.textColor = RGB_HEX(0x111111);
    title.font = SYSTEMFONT(15);
    [self.bgView addSubview:title];
    
    [title mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.bgView.mas_top).offset(12);
        make.height.equalTo(@21);
        make.centerX.equalTo(self.bgView.mas_centerX);
    }];
    
    UIView * lineView = [[UIView alloc]init];
    lineView.backgroundColor = RGB_HEX(0xe6e6e6);
    [self.bgView addSubview:lineView];
    
    [lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(title.mas_bottom).offset(12);
        make.left.right.equalTo(self.bgView);
        make.height.equalTo(@0.5);
    }];
    
    [self.weChatBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lineView.mas_bottom).offset(39);
        make.left.mas_equalTo(self.bgView.mas_left).offset(36);
        make.size.mas_equalTo(CGSizeMake(64, 64));
    }];
    
    [self.friendBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lineView.mas_bottom).offset(39);
        make.centerX.equalTo(self.bgView.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(64, 64));
    }];
    
    [self.QRBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(lineView.mas_bottom).offset(39);
        make.right.mas_equalTo(self.bgView.mas_right).offset(-36);
        make.size.mas_equalTo(CGSizeMake(64, 64));
    }];
    
    [self.weChatLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.weChatBtn.mas_bottom).offset(6);
        make.centerX.mas_equalTo(self.weChatBtn.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(40, 10));
    }];
    
    [self.friendLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.friendBtn.mas_bottom).offset(6);
        make.centerX.mas_equalTo(self.friendBtn.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(40, 10));
    }];
    
    [self.QRLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(self.QRBtn.mas_bottom).offset(6);
        make.centerX.mas_equalTo(self.QRBtn.mas_centerX);
        make.size.mas_equalTo(CGSizeMake(40, 10));
    }];
    
    
    
    
}

#pragma mark - click event
- (void)didClickedWeChatButton {
    self.hidden = YES;
    if (self.block) {
        self.block(ShareTypeWeChat);
    }
}

- (void)didClickedQQButton {
    self.hidden = YES;
    
    if (self.block) {
        self.block(ShareTypeFriend);
    }
}


- (void)didClickedQRCodeButton {
//    dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
//        self.hidden = YES;
//    });
    self.hidden = YES;
    if (self.block) {
        self.block(ShareTypeQRCode);
    }
}


- (void)didClickedCancelButton {
    self.hidden = YES;
}


#pragma mark - getters & setters
- (UIView *)bgView {
    if (!_bgView) {
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = [UIColor whiteColor];
    }
    return _bgView;
}

- (UIButton *)weChatBtn {
    if (!_weChatBtn) {
        _weChatBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_weChatBtn setBackgroundImage:[UIImage imageNamed:@"pic_yaoqing_wechat"] forState:UIControlStateNormal];
        
        [_weChatBtn addTarget:self action:@selector(didClickedWeChatButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _weChatBtn;
}

- (UIButton *)friendBtn {
    if (!_friendBtn) {
        _friendBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_friendBtn setBackgroundImage:[UIImage imageNamed:@"pic_yaoqing_friendsc"] forState:UIControlStateNormal];
        
        [_friendBtn addTarget:self action:@selector(didClickedQQButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _friendBtn;
}

- (UIButton *)QRBtn {
    if (!_QRBtn) {
        _QRBtn = [UIButton buttonWithType:UIButtonTypeCustom];
        [_QRBtn setBackgroundImage:[UIImage imageNamed:@"pic_yaoqing_erweima"] forState:UIControlStateNormal];
        
        [_QRBtn addTarget:self action:@selector(didClickedQRCodeButton) forControlEvents:UIControlEventTouchUpInside];
    }
    return _QRBtn;
}


- (UILabel *)weChatLabel {
    if (!_weChatLabel) {
        _weChatLabel = [[UILabel alloc] init];
        _weChatLabel.text = @"微信";
        _weChatLabel.font = SYSTEMFONT(12);
        _weChatLabel.textColor = RGB_HEX(0x333333);
        _weChatLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _weChatLabel;
}

- (UILabel *)friendLabel {
    if (!_friendLabel) {
        _friendLabel = [[UILabel alloc] init];
        _friendLabel.text = @"朋友圈";
        _friendLabel.font = SYSTEMFONT(12);
        _friendLabel.textColor = RGB_HEX(0x333333);
        _friendLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _friendLabel;
}

- (UILabel *)QRLabel {
    if (!_QRLabel) {
        _QRLabel = [[UILabel alloc] init];
        _QRLabel.text = @"二维码";
        _QRLabel.font = SYSTEMFONT(12);
        _QRLabel.textColor = RGB_HEX(0x333333);
        _QRLabel.textAlignment = NSTextAlignmentCenter;
    }
    return _QRLabel;
}





@end
